package com.academy.querystapp;

import com.academy.student.StudentActivity;
import com.academy.teacher.TeacherActivty;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;

public class HomeActivity extends Activity implements OnClickListener
{
	
	Button btnTeacher,btnStudent;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initializeViews();
	}
	
	public void initializeViews()
	{
		btnStudent=(Button) findViewById(R.id.btnStudent);
		btnTeacher=(Button) findViewById(R.id.btnTeacher);
		btnStudent.setOnClickListener(this);
		btnTeacher.setOnClickListener(this);
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

	@Override
	public void onClick(View v) 
	{
		
		if(v==btnStudent)
		{
			Intent ii=new Intent(this,StudentActivity.class);
			startActivity(ii);
		}
		
		if(v==btnTeacher)
		{
			Intent ii=new Intent(this,TeacherActivty.class);
			startActivity(ii);
			
		}
		
	}

	public void onBackPressed() 
	{
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setMessage("Are you sure you want to exit?")
       .setCancelable(false)
       .setPositiveButton("Yes", new DialogInterface.OnClickListener() 
       	 {
	   		public void onClick(DialogInterface dialog, int id) 
	   		{		    	   			
    	   		Intent intent = new Intent(Intent.ACTION_MAIN);
    	   		intent.addCategory(Intent.CATEGORY_HOME);
    	   		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    	   		startActivity(intent);
    	   		finish();
	   		}
       	 }
    		   )       
        .setNegativeButton("No", new DialogInterface.OnClickListener() 
        {
           public void onClick(DialogInterface dialog, int id) 
           {
                dialog.cancel();
           }
        }
        );
		final AlertDialog alert = builder.create();	
		alert.show();
	 }
	
	
	
}
